<?php
class CMRPageCreateResource extends CMRPage
{
	public function __construct($database)
	{
		parent::__construct($database);
		if($this->getAction()=='InsertRecord')
		{
			$callback = new DataTableCallback($this->Database->Recopy(), $this->UserID);
			$callback->insertRecord($_POST['DBTableName']);
		}
	}
	
	protected function getContentsDiv()
	{
		
		$html = "<div id=\"content\">\n";
		$html .= "<h1>Create a Resource</h1>";

		$hidden = new Hidden();
		$hidden->setName("SubAction");
		$html .= $hidden->getHTML();
		
		$script = new EditDeleteFormScript();
		$html .= $script->getHTML();

//		echo "CMRPageCreateResource SubAction = ".$this->getSubAction()."<br>\n";
		
		switch ($this->getSubAction())
		{
			case 'submitCreateFile':
				$html .= $this->getCreateFile();			
				break;
				
			case 'submitCreateComposer':
				$html .= $this->getCreateComposer();			
				break;
				
			case 'submitCreateLink':
				$html .= $this->getCreateLink();			
				break;
				
			case 'submitCreateRepertoire Item':
				$html .= $this->getCreateRepertoire();			
				break;
				
/*			case 'submitCreateScore':
				$html .= $this->getCreateScore();			
				break;*/
				
			default:
				$html .= $this->getDefault();			
				break;
		}
		
		
		$html .= "</div>";
		return $html;
	}
	
	private function getDefault()
	{
		$html = "<p>Select the type of resource you wish to add from the dropdown list below.</p>";
		$values = new Enumeration($this->Database,'ResourceTypes');
		$list = new DropDownListEnumeration($values->getArray());
		$list->setName("SubmitType");
		$html .= $list->getHTML();
		
		$button = new JavascriptButton();
		$button->setValue("Next");
		$button->setJavascript("var submitaction; submitaction='submitCreate'+(document.getElementById('SubmitType').options[document.getElementById('SubmitType').selectedIndex].text); document.getElementById('Action').value = 'adminCreateResource'; document.getElementById('SubAction').value = submitaction; document.getElementById('PageForm').submit();");
		$html .= $button->getHTML();
		return $html;
	}

	private function getCreateFile()
	{
		$hidden = new Hidden();
		$hidden->setName("RecordID");
		$html = $hidden->getHTML();
		
		$hidden = new Hidden();
		$hidden->setName("DBTableName");
		$html .= $hidden->getHTML();
		
		$hidden = new Hidden();
		$hidden->setName("InsertRecord_Resources_StatusTypeID");
		$hidden->setValue('1'); // created
		$html .= $hidden->getHTML();
		
		$script = new UpdateRecordScript();
		$html .= $script->getHTML();
		$panel = new PanelEditDBRecord($this->Database,'Resources',-1);
		$panel->setTypeTable('ResourceTypeID','Files',6);
		$panel->addReadOnlyField('StatusTypeID');
		$panel->setIncludeCommentField(true);
		$html .= $panel->getHTML();
		return $html;
	}
	

	private function getCreateComposer()
	{
		$hidden = new Hidden();
		$hidden->setName("RecordID");
		$html = $hidden->getHTML();
		
		$hidden = new Hidden();
		$hidden->setName("DBTableName");
		$html .= $hidden->getHTML();
		
		$hidden = new Hidden();
		$hidden->setName("InsertRecord_Resources_StatusTypeID");
		$hidden->setValue('1');
		$html .= $hidden->getHTML();
		
		$script = new UpdateRecordScript();
		$html .= $script->getHTML();
		$panel = new PanelEditDBRecord($this->Database,'Resources',-1);
		$panel->setTypeTable('ResourceTypeID','Composers',3);
		$panel->addReadOnlyField('StatusTypeID');
		$panel->setIncludeCommentField(true);
		$panel->setYearRange(1200,2020);
		$panel->setDateDisabler(true);
		$html .= $panel->getHTML();
		return $html;
	}
	
	private function getCreateLink()
	{
		$hidden = new Hidden();
		$hidden->setName("RecordID");
		$html = $hidden->getHTML();
		
		$hidden = new Hidden();
		$hidden->setName("DBTableName");
		$html .= $hidden->getHTML();
		
		$hidden = new Hidden();
		$hidden->setName("InsertRecord_Resources_StatusTypeID");
		$hidden->setValue('1');
		$html .= $hidden->getHTML();
		
		$script = new UpdateRecordScript();
		$html .= $script->getHTML();
		$panel = new PanelEditDBRecord($this->Database,'Resources',-1);
		$panel->setTypeTable('ResourceTypeID','Links',7);
		$panel->addReadOnlyField('StatusTypeID');
		$panel->setIncludeCommentField(true);
		//		$panel->setYearRange(1400,2020);
		$html .= $panel->getHTML();
		return $html;
	}
	
	private function getCreateRepertoire()
	{
		$hidden = new Hidden();
		$hidden->setName("RecordID");
		$html = $hidden->getHTML();
		
		$hidden = new Hidden();
		$hidden->setName("DBTableName");
		$html .= $hidden->getHTML();
		
		$hidden = new Hidden();
		$hidden->setName("InsertRecord_Resources_StatusTypeID");
		$hidden->setValue('1');
		$html .= $hidden->getHTML();
		
		$script = new UpdateRecordScript();
		$html .= $script->getHTML();
		$panel = new PanelEditDBRecord($this->Database,'Resources',-1);
		$panel->setTypeTable('ResourceTypeID','RepertoireItems',2);
		$panel->addReadOnlyField('StatusTypeID');
		$panel->setIncludeCommentField(true);
		//		$panel->setYearRange(1400,2020);
		$html .= $panel->getHTML();
		return $html;
		
	}
	
}
?>